<?php
Yii::app()->clientScript->registerScriptFile($this->staticsPath."/frontend/js/jquery.js",CClientScript::POS_HEAD);
Yii::app()->clientScript->registerCssFile($this->staticsPath."/css/global.css");
Yii::app()->clientScript->registerCssFile($this->staticsPath."/css/index.css");
Yii::app()->clientScript->registerCssFile($this->staticsPath."/css/font-awesome.min.css");
Yii::app()->clientScript->registerCssFile($this->staticsPath."/Font-Awesome-3.2.1/css/font-awesome.min.css");

Yii::app()->clientScript->registerScriptFile($this->staticsPath."/frontend/js/bootstrap.min.js",CClientScript::POS_HEAD);
Yii::app()->clientScript->registerCssFile($this->staticsPath."/frontend/css/bootstrap.min.css");
Yii::app()->clientScript->registerScriptFile($this->staticsPath."/start/jquery.raty.js",CClientScript::POS_HEAD);
Yii::app()->clientScript->registerScriptFile($this->staticsPath."/js/alert.js",CClientScript::POS_HEAD);



Yii::app()->clientScript->registerCss("CSS1","
    .cont_box img{
        height: 200px;
    }

   #loadings {
        left: 50%;
        position: absolute;
        top: 50%;
    }

");


?>
<style type="text/css">
    .main-box {
        background: #FDF2B9 url("<?php echo $this->staticsPath."/img/showbg.png" ?>") no-repeat scroll 0 0 / 100% auto;
        height: 100%;
        left: 0;
        margin: 0 auto;
        position: absolute;
        top: 0;
        width: 100%;
        z-index: -1;
    }
    .morcon {
        height: 100px;
        margin: 245px 20px 20px;
        position: relative;
        text-align: center;
    }

    .morcon .reg {
        background: rgba(255, 255, 255, 0) none repeat scroll 0 0;
        border: medium none;
        color: #fff;
        font-size: 20px;
        left: 4%;
        position: absolute;
        top: 0;
    }
    .morcon .login {
        background: rgba(255, 255, 255, 0) none repeat scroll 0 0;
        border: medium none;
        color: #fff;
        display: block;
        font-size: 20px;
        left: 51%;
        position: absolute;
        top: 39%;
    }

    .wrap .header{
        width: 100%;
        position: relative;
        height: 240px;
    }
    .wrap .footer {
        height: 300px;
        position: relative;
        width: 100%;
    }

    .wrap .header .mydodo{
         background: url("<?php echo $this->staticsPath."/img/mydodo.png" ?>") no-repeat scroll 0 0 / 150px auto;
         height: 40px;
         width: 150px;
         position: absolute;
         right: 15px;
         top: 25px;
     }
    .wrap .header .imgbg {
        height: 175px;
        left: 25px;
        overflow: hidden;
        position: relative;
        top: 15px;
        width: 130px;
    }


    .imgbg img {
        height: 100%;
        position: absolute;
    }
    .wrap .header .hname {
        height: 200px;
        left: 170px;
        position: absolute;
        top: 15px;
        width: 200px;
    }
    .wrap .header .hname p{
        color: #0066b3;
        display: inline-block;
        font-size: 18px;
        width: 145px;
    }
    .wrap .header .list {


        height: 80px;
        left: 25px;
        position: absolute;
        top: 25px;
        width: 80px;
    }
    .wrap .header .list a{
        color: #0066b3;
        font-size: 30px;
    }
    .wrap .footer .fbotton{
        width: 33%;
        height: 150px;
        float: left;
    }
    .wrap .footer .fbotton .like{
        background: url("<?php echo $this->staticsPath."/img/mylike.png" ?>") no-repeat scroll 13px 0 / 90px auto;
        height: 100%;
        width: 100%;
    }
    .wrap .footer .fbotton .collection{
        background: url("<?php echo $this->staticsPath."/img/mycollection.png" ?>") no-repeat scroll 13px 0 / 104px auto;
        height: 100%;
        width: 100%;
    }
    .wrap .footer .share{
        background: url("<?php echo $this->staticsPath."/img/share_xd.png" ?>") no-repeat scroll -2px 15px / 130px auto;
        bottom: 10px;
        height: 70px;
        left: 30px;
        position: fixed;
        width: 200px;
    }
    .wrap .footer .fbotton .point{
        background: url("<?php echo $this->staticsPath."/img/point.png" ?>") no-repeat scroll 6px 0 / 104px auto;
        height: 100%;
        width: 100%;
    }
    .wrap .footer .fbotton .pointlist{
        background: url("<?php echo $this->staticsPath."/img/pointlist.png" ?>") no-repeat scroll 13px 0 / 90px auto;
        height: 100%;
        width: 100%;
    }
    .wrap .footer .fbotton .pointgift{
        background: url("<?php echo $this->staticsPath."/img/pointgift.png" ?>") no-repeat scroll 13px 11px / 90px auto;
        height: 100%;
        width: 100%;
    }
    body{
        background: #FDF2B9 none repeat scroll 0 0;
    }
    .hname .bt{
        width: 100px;
        height: 30px;
        line-height: 30px;
        border-radius: 6px;
        background: #57b6e4 none repeat scroll 0 0;
        display: block;
        text-align: center;
        margin-bottom: 5px;
        border-bottom: 2px solid #fff;
    }
    .hname .bt.qd{
        background: #fac037 none repeat scroll 0 0;
        border-bottom: 2px solid #976b3d;
    }
    .hname .bt.yd{
        background: #e83631 none repeat scroll 0 0;
        border-bottom: 2px solid #910c04;
    }
    .hname .sc{
        background: url("<?php echo $this->staticsPath."/img/sc_start.png" ?>") no-repeat scroll 0 0;
        display: inline-block;
        height: 25px;
        margin-bottom: 10px;
        margin-right: 10px;
        width: 25px;
    }
    .hname .sc.end{
        background: url("<?php echo $this->staticsPath."/img/sc_end.png" ?>") no-repeat scroll 0 0;
    }
    .hname .xh{
        background: url("<?php echo $this->staticsPath."/img/xh_start.png" ?>") no-repeat scroll 1px 0;
        display: inline-block;
        height: 25px;
        margin-bottom: 10px;
        margin-right: 10px;
        width: 27px;
    }
    .hname .xh.end{
        background: url("<?php echo $this->staticsPath."/img/xh_end.png" ?>") no-repeat scroll 1px 0;
    }
    .morcons {
        height: 28px;
        margin: 20px;
        position: relative;
        text-align: center;
    }
    .morcons a {
        background: #fff none repeat scroll 0 0;
        border: 1px solid #e2e1e1;
        border-radius: 4px;
        color: #333;
        font-size: 14px;
        padding: 6px 50px;
    }
    .wrap .content{
        padding:0 20px ;
        color: #525252;
    }
    .footer .xd_share{
        background: url("<?php echo $this->staticsPath."/img/xd1.png" ?>") no-repeat scroll 0 0 / 130px auto;
        height: 40px;
        margin-left: 20px;
        margin-top: 10px;
        width: 130px;
    }
    .footer .comment{
        position: relative;
    }
    .footer .comment li {
        border-bottom: 2px dashed #00a4de;
        margin: auto;
        padding: 2% 0;
        width: 90%;
    }
    .top_box .tx {
        float: left;
        height: 60px;
        margin-right: 10px;
        width: 60px;
    }
    .top_box .wz {
        display: block;
        float: left;
        margin-top: 10px;
        width: 110px;
        overflow: hidden;
    }
    .top_box .tx img{
        width: 100%;height: 100%;
    }
    .top_box .an{
        float: right;
        width: 100px;
    }
    .top_box .an .zan{
        background: url("<?php echo $this->staticsPath."/img/xin.png" ?>") no-repeat scroll 0 0 / 40px auto;
        height: 60px;
        width: 60px;
        float: left;
        cursor:pointer;
        padding-top: 35px;
    }
    .top_box .an .pinglun{
        background: url("<?php echo $this->staticsPath."/img/pinglun.png" ?>") no-repeat scroll 0 0 / 40px auto;
        height: 40px;
        width: 40px;
        cursor:pointer;
        float: left;
    }
    .plbox {
        border-top: 1px dashed #c8bf92;
        margin-left: 30px;
        margin-top: 10px;
    }
    .con{
        padding: 10px 0;
        word-break: break-all;
    }
    .nm{
        color: #0066b3;
    }
    .hname-box{
        width: 100%;
        height: 40px;
        line-height: 40px;
    }
    #loading {
        font-size: 30px;
        height: 50px;
        margin: 0 auto;
        text-align: center;
        width: 100px;
    }
    .alert-error {
        color: #b94a48;
    }
    .alert {
        border-radius: 4px;
        margin-bottom: 20px;
        padding: 8px;
        text-align: center;
        text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
    }
    .plbox .sb .top_box .name {
        word-break: break-all;
    }
</style>
<?php if($status=='no'){ ?>
    <div  class="loading" style="display: block">
        <div id="loading">
            <div id="loadings">
                <i class="fa fa-cog fa-spin"></i>
            </div>
        </div>
    </div>
<?php } ?>
<div class="data"  <?php if($status=='no'){ ?>style="display: none"<?php } ?>>
    <div class="main-box"></div>
<!--    <header class="homeHder header">-->
<!--        --><?php //if($app_info->is_type==3){ ?>
<!--        <a href="javascript:history.go(-2)">-->
<!--            <div class="hder_return flol">-->
<!--                <i class="size fa fa-angle-left"></i>-->
<!--            </div>-->
<!--        </a>-->
<!--        --><?php //}else{ ?>
<!--        <a href="javascript:history.go(-1)">-->
<!--            <div class="hder_return flol">-->
<!--                <i class="size fa fa-angle-left"></i>-->
<!--            </div>-->
<!--        </a>-->
<!--        --><?php //} ?>
<!--        <div class="hder_logo">书籍详情</div>-->
<!--    </header>-->
    <section class="wrap">
        <div class="header">
            <div id="imgbg" class="imgbg">
                    <img src="<?php echo Yii::app()->params['webPath'].$book_info->thumb; ?>">
            </div>
            <div class="hname">
                <p><?php echo $book_info->title ?></p>
                <p style="font-size: 14px;color: #000">阅读数 : <b style="color: darkred"><?php echo $yuedu; ?></b></p>
                <?php if($user_info->role==1){ ?>
                <div class="hname-box">
                    <div id="jrxh" class="xh <?php if($is_Good){ ?>end<?php } ?> "></div>
                    <div id="jrsc"  class="sc <?php if($is_Store){ ?>end<?php } ?>"></div>
                </div>
                <?php if($is_Yuedu){ ?>
                <div id="ydqd"  class="bt qd">已签到</div>
                <?php }else{ ?>
                <div id="ydqd"  class="bt qd">签到</div>
                <?php } ?>
                <div id="ljyd" class="bt yd">立即阅读</div>
                <?php }else{ ?>
                    <div  style="color: darkred; font-weight: 600; margin-bottom: 10px;"  >点击数：<?php echo intval($book_info->click) ?></div>
                    <div  style="color: darkgreen; font-weight: 600; margin-bottom: 10px;" >喜欢数：<?php echo intval($book_info->good); ?></div>
                <?php } ?>
            </div>
        </div>
        <div class="content">
            <?php echo $book_info->description ?>
        </div>
        <div class="footer">
            <div class="xd_share"></div>
            <ul class="comment" id="comm">
                <?php foreach($comment as $v){ ?>
                <li>
                    <div class="sb">
                        <div class="top_box">
                            <?php if(!$v['image']){ ?>
                                <?php if($v['sex'] ==1){ ?>
                                    <div class="tx"><img src="<?php echo $this->staticsPath."/img/tx1.jpg" ?>" /></div>
                                <?php }else{ ?>
                                    <div class="tx"><img src="<?php echo $this->staticsPath."/img/tx2.jpg" ?>" /></div>
                                <?php } ?>
                            <?php }else{ ?>
                            <div class="tx"><img src="<?php echo $v['image']; ?>" /></div>
                            <?php } ?>
                            <div class="wz">
                                <div class="name nm"><?php echo $v['user_name']  ?></div>
                                <div class="time"><?php echo date('Y/m/d H:i',$v['create_time'])  ?></div>
                            </div>
                            <?php if($user_info->role==2){ ?>
                                <?php if($v['pid']==$user_info->relation_id){ ?>
                                <div class="an">
                                    <div data-id="<?php echo $v['id']  ?>" class="zan"><span style="color: maroon; font-weight: 900; display: block; text-align: center; margin-left: 0px; width: 40px;"><?php echo intval($v['good'])  ?></span></div>
                                    <div data-id="<?php echo $v['id']  ?>" class="pinglun"></div>
                                </div>
                                <?php } ?>
                            <?php }else{ ?>
                                <div class="an">
                                    <div data-id="<?php echo $v['id']  ?>" class="zan"><span style="color: maroon; font-weight: 900; display: block; text-align: center; margin-left: 0px; width: 40px;"><?php echo intval($v['good'])  ?></span></div>
                                    <div data-id="<?php echo $v['id']  ?>" class="pinglun"></div>
                                </div>
                            <?php } ?>

                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="con"><?php echo CHtml::decode($v['content']);  ?></div>
                    <?php $comment_info =  BookComment::model()->getComment($v['id']); ?>
                    <div class="pinglunbox">
                        <div id="plbox_<?php echo $v['id'] ?>" class="plbox">
                    <?php if($comment_info){ ?>
                        <?php foreach($comment_info as $vv){ ?>
                        <div class="sb">
                            <div class="top_box">
                                <?php if($vv['role']==1){ ?>
                                    <div class="name"><span class="nm"><?php echo $vv['user_name'] ?></span>：<?php echo $vv['content'] ?></div>
                                <?php }elseif($vv['role']==2){ ?>
                                    <div class="name"><span class="nm"><?php echo $v['user_name'].'的'.$vv['is_relation'] ?></span>：<?php echo $vv['content'] ?></div>
                                <?php }elseif($vv['role']==3){ ?>
                                    <div class="name"><span class="nm"><?php echo $vv['user_name'].'教师' ?></span>：<?php echo $vv['content'] ?></div>
                                <?php } ?>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                        <?php } ?>
                    <?php } ?>
                        </div>
                    </div>
                </li>
                <?php } ?>
            </ul>

            <div id="loading" style="display: none"><i class="fa fa-spinner fa-spin"></i></div>
            <div id="alt" style="display: none" class="alert alert-error">
                已经到底啦！
            </div>

            <br/><br/><br/>
            <?php if($user_info->role==1){ ?>
                <?php if($is_comment ==0){ ?>
            <div id="share" class="share"></div>
            <?php }}elseif($user_info->role==3){ ?>
                <?php if($is_comment ==0){ ?>
            <div id="lsshare" class="share"></div>
            <?php }} ?>
        </div>
    </section>
</div>
<div class="modal fade" id="linkModal-d" data-id="1" tabindex="-1" role="dialog" aria-labelledby="linkModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <!-- 登陆页面注册提示 -->
        <div class="modal-content text-left">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">请输入读书心得</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label for="exampleInputname1">读书心得：</label>
                        <textarea style="height:200px" class="form-control" id="xinde" ></textarea>
                    </div>
                    <button type="button"  onclick="submitForm();" class="btn btn-primary btn-block btn-lg">确认提交</button>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="linkModal-e" data-id="1" tabindex="-1" role="dialog" aria-labelledby="linkModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <!-- 登陆页面注册提示 -->
        <div class="modal-content text-left">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">请输入读书评价</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label for="exampleInputname1">读书评价：</label>
                        <textarea style="height:200px" class="form-control" id="lsxinde" ></textarea>
                    </div>
                    <button type="button" id="lssubmitbook"  class="btn btn-primary btn-block btn-lg">确认提交</button>
                </form>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="XcommXd" data-id="1" tabindex="-1" role="dialog" aria-labelledby="linkModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <!-- 登陆页面注册提示 -->
        <div class="modal-content text-left">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">请输入评论</h4>
            </div>
            <div class="modal-body">
                <form>
                    <div class="form-group">
                        <label for="exampleInputname1">评论：</label>
                        <textarea data-id="" style="height:200px" class="form-control" id="pl" ></textarea>
                    </div>
                    <button type="button"  id="plSubmit" class="btn btn-primary btn-block btn-lg">确认提交</button>
                </form>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="XcommLs" data-id="1" tabindex="-1" role="dialog" aria-labelledby="linkModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <!-- 登陆页面注册提示 -->
        <div class="modal-content text-left">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">请输入评价</h4>
            </div>
            <div class="modal-body">
                <form>

                    <div class="form-group">
                        <label for="exampleInputname1">打分：</label>
                        <div id="star"></div>
                    </div>

                    <div class="form-group">
                        <label for="exampleInputname1">评价：</label>
                        <textarea data-id="" style="height:200px" class="form-control" id="lspl" ></textarea>
                    </div>
                    <button type="button"  id="lsSubmit" class="btn btn-primary btn-block btn-lg">确认提交</button>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="Xalert" data-id="1" tabindex="-1" role="dialog" aria-labelledby="linkModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <!-- 登陆页面注册提示 -->
        <div class="modal-content text-left">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">提示</h4>
            </div>
            <div class="modal-body">
                <p id="alertMassage"></p>
                <button type="button" style="margin-top: 20px" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function(){
        $('#star').raty({

            iconRange: [
                { range: 1, on: '<?php echo $this->staticsPath."/start/img/star-on.png" ?>', off: '<?php echo $this->staticsPath."/start/img/star-off.png" ?>' },
                { range: 2, on: '<?php echo $this->staticsPath."/start/img/star-on.png" ?>', off: '<?php echo $this->staticsPath."/start/img/star-off.png" ?>' },
                { range: 3, on: '<?php echo $this->staticsPath."/start/img/star-on.png" ?>', off: '<?php echo $this->staticsPath."/start/img/star-off.png" ?>' },
                { range: 4, on: '<?php echo $this->staticsPath."/start/img/star-on.png" ?>', off: '<?php echo $this->staticsPath."/start/img/star-off.png" ?>' },
                { range: 5, on: '<?php echo $this->staticsPath."/start/img/star-on.png" ?>', off: '<?php echo $this->staticsPath."/start/img/star-off.png" ?>' }
            ]
        });
        var zanlock = true;
        $("body").delegate(".zan",'click',function(){
            var _this = $(this);
            var cid = _this.attr('data-id');
            if(zanlock==true){
                $.ajax({
                    type: "POST",
                    url: '<?php echo Yii::app()->createUrl('index/ajaxZan'); ?>',
                    data: {
                        cid:cid,
                        bid:'<?php echo $book_info->id ?>'
                    },
                    beforeSend:function(){
                        zanlock = false;
                    },
                    dataType: "json",
                    success: function (data) {
                        if (data) {
                            zanlock=true;
                            if(data.status==1){
                                var num = parseInt(_this.find('span').html()) + 1;
                                _this.find('span').html(num);
                                alert(data.message);
                            }else{
                                alert(data.message);
                            }
                        }else{
                            zanlock=true;
                            alert('点赞失败');
                        }
                    }
                });
            }
        });
    });











    $("body").on('click',".pinglun",function(event){
        event.stopPropagation();
        var _this = $(this);
        var cid = _this.attr('data-id');
        var role = '<?php echo $user_info->role ?>';
        if(role==3){
            $("#lspl").val('');
            $("#lspl").attr('data-id',cid);
            $("#XcommLs").modal();
        }else{//其他
            //清空数据
            $("#pl").val('');
            $("#pl").attr('data-id',cid);
            $("#XcommXd").modal();
        }
    });

    // AJAX提交数据
    var lssubmitlock = true;
    $("#lssubmitbook").click(function(){
        if(lssubmitlock==true){
            var xinde 			= $("#lsxinde").val();
            if (xinde.length == 0 || xinde.length < 20) {
                alert("评价不能为空或小于20个字符限制");
                return;
            };
            $.ajax({
                type: "POST",
                url: '<?php echo Yii::app()->createUrl('index/ajaxBookComment'); ?>',
                data: {
                    bid:'<?php echo $book_info->id ?>',
                    xinde:xinde,
                    role:3
                },
                dataType: "json",
                beforeSend:function(){
                    lssubmitlock = false;
                },
                success: function (data) {
                    if (data) {
                        if(data.status==1){
                            lssubmitlock = true;
                            alert(data.message);
                            $('#linkModal-e').modal('hide');
                            $("#lsxinde").val('');
                            $("#comm").prepend(data.html);
                        }else{
                            lssubmitlock = true;
                            alert(data.message);
                            $('#linkModal-e').modal('hide');
                            $("#lsxinde").val('');
                        }
                    }else{
                        lssubmitlock = true;
                        alert('发布心得失败');
                        $('#linkModal-e').modal('hide');
                    }
                }
            });
        }
    });
    $("#lsSubmit").click(function(){
        var pl = $("#lspl").val();
        var cid = $("#lspl").attr('data-id');
        var start = $("#star").find('input').val();
        if (start ==''){
            $("#alertMassage").html("你还没有评星哦");
            $("#Xalert").modal();
            setTimeout(function(){$("#Xalert").modal('hide')},2000);
            return;
        }
        if (pl.length == 0 || pl.length < 10) {
            $("#alertMassage").html("评论不能为空或小于10个字符限制");
            $("#Xalert").modal();
            setTimeout(function(){$("#Xalert").modal('hide')},2000);
            return;
        };
        $.ajax({
            type: "POST",
            url: '<?php echo Yii::app()->createUrl('index/ajaxPl'); ?>',
            data: {
                bid:'<?php echo $book_info->id ?>',
                cid:cid,
                pl:pl,
                start:start
            },
            dataType: "json",
            success: function (data) {
                if (data) {
                    if(data.status==1){
                        $("#alertMassage").html(data.message);
                        $("#Xalert").modal();
                        setTimeout(function(){$("#Xalert").modal('hide')},2000);
                        $("#XcommLs").modal('hide');
                        $("#lspl").val('');
                        var html = '';
                        html +='<div class="sb">';
                        html +='<div class="top_box">';
                        html +='<div class="name"><span class="nm">我</span>：'+pl+'</div>';
                        html +='</div>';
                        html +='<div class="clearfix"></div>';
                        html +='</div>';
                        $("#plbox_"+cid).prepend(html);
                    }else{

                        $("#XcommLs").modal('hide');
                        $("#alertMassage").html(data['message']);
                        $("#Xalert").modal();
                        $("#lspl").val('');
                    }
                }else{
                    $("#alertMassage").html("评论失败");
                    $("#Xalert").modal();
                    setTimeout(function(){$("#Xalert").modal('hide')},2000);
                }
            }
        });
    });


    $("#plSubmit").click(function(){
        var pl = $("#pl").val();
        var cid = $("#pl").attr('data-id');

        if (pl.length == 0 || pl.length < 10) {
            $("#alertMassage").html("评论不能为空或小于10个字符限制");
            $("#Xalert").modal();
            setTimeout(function(){$("#Xalert").modal('hide')},2000);
            return;
        };
        $.ajax({
            type: "POST",
            url: '<?php echo Yii::app()->createUrl('index/ajaxPl'); ?>',
            data: {
                bid:'<?php echo $book_info->id ?>',
                cid:cid,
                pl:pl
            },
            dataType: "json",
            success: function (data) {
                if (data) {
                    if(data['status']==1){
                        $("#alertMassage").html(data.message);
                        $("#Xalert").modal();
                        setTimeout(function(){$("#Xalert").modal('hide')},2000);
                        $("#XcommXd").modal('hide');
                        $("#pl").val('');
                        var html = '';
                        html +='<div class="sb">';
                        html +='<div class="top_box">';
                        html +='<div class="name"><span class="nm">我</span>：'+pl+'</div>';
                        html +='</div>';
                        html +='<div class="clearfix"></div>';
                        html +='</div>';
                        $("#plbox_"+cid).prepend(html);
                    }else{
                        $("#XcommXd").modal('hide');
                        $("#alertMassage").html(data['message']);
                        $("#Xalert").modal();
                        $("#pl").val('');
                    }
                }else{

                    alert('评论失败');
                }
            }
        });
    });


    $(function(){
        var currentPage = 0;
        var isloading = false;
        $(window).scroll(function(){
            if($(window).scrollTop() + 100 >= $(document).height() - $(window).height()){
                if (isloading == true){  //如果loading为真 则return false;
                    return false;
                }
                currentPage = currentPage + 1;
                isloading = true; //为真了
                $.ajax({
                    url:'<?php echo Yii::app()->createUrl('index/ajaxComment'); ?>',
                    type : 'GET',
                    data:{
                        page:currentPage,
                        bid:'<?php echo $book_info->id ?>',
                        pid:'<?php echo $user_info->id ?>'
                    },
                    dataType:'html',
                    beforeSend : function() {
                        $('#loading').show();
                        isloading = true;
                    },
                    success : function (data,response,status) {
                        if(data){
                            $('#comm').append(data);
                            isloading = false;
                            $('#loading').hide();
                        }else{
                            isloading = true;
                            $('#loading').hide();
                            $('#alt').show();
                        }




                    }
                });
            }

        });









       var ljydlock = true;
       $("#ljyd").click(function(){
            if(ljydlock==true){
                $.ajax({
                    type: "POST",
                    url: '<?php echo Yii::app()->createUrl('index/ajaxYuedu'); ?>',
                    data: {
                        bid:'<?php echo $book_info->id ?>'
                    },
                    dataType: "json",
                    beforeSend:function(){
                        ljydlock = false;
                    },
                    success: function (data) {
                        if (data) {
                            if(data.status==1){
                                ljydlock = true;
                                alert(data.message);
                            }else if(data.status==2){
                                window.location.href='<?php echo $this->createUrl('guideShow',array('id'=>$book_info->id,'openid'=>$openid)) ?>';
                            }else{
                                ljydlock = true;
                                alert(data.message);
                            }
                        }else{
                            ljydlock = true;
                            alert('加入立即阅读失败');
                        }
                    }
                });
            }else{

            }
       });


        var ydqdlock = true;
        $("#ydqd").click(function(){
            if(ydqdlock==true){
                $.ajax({
                    type: "POST",
                    url: '<?php echo Yii::app()->createUrl('index/ajaxQiandao'); ?>',
                    data: {
                        bid:'<?php echo $book_info->id ?>'
                    },
                    dataType: "json",
                    beforeSend:function(){
                        ydqdlock = false;
                    },
                    success: function (data) {
                        if (data) {
                            if(data.status==1){
                                $("#ydqd").html('已签到');
                                alert(data.message);
                            }else{
                                ydqdlock = true;
                                alert(data.message);
                            }
                        }else{
                            ydqdlock = true;
                            alert('签到失败');
                        }
                    }
                });
            }else{

            }
        });

        var jrxhlock = true;
        $("#jrxh").click(function(){
            if(jrxhlock==true){
                $.ajax({
                    type: "POST",
                    url: '<?php echo Yii::app()->createUrl('index/ajaxXihuan'); ?>',
                    data: {
                        bid:'<?php echo $book_info->id ?>'
                    },
                    dataType: "json",
                    beforeSend:function(){
                        jrxhlock = false;
                        if($("#jrxh").hasClass("end")){
                            $("#jrxh").removeClass("end");
                        }else{
                            $("#jrxh").addClass("end");
                        }
                    },
                    success: function (data) {
                        if (data) {
                            if(data.status==1){
                                jrxhlock = true;
                                alert(data.message);
                            }else{
                                jrxhlock = true;
                                alert(data.message);
                            }
                        }else{
                            jrxhlock = true;
                            alert('加入喜欢失败');
                        }
                    }
                });
            }else{

            }
        });
        var jrsclock = true;
        $("#jrsc").click(function(){
            if(jrsclock==true){
                $.ajax({
                    type: "POST",
                    url: '<?php echo Yii::app()->createUrl('index/ajaxShoucang'); ?>',
                    data: {
                        bid:'<?php echo $book_info->id ?>'
                    },
                    dataType: "json",
                    beforeSend:function(){
                        jrsclock = false;
                        if($("#jrsc").hasClass("end")){
                            $("#jrsc").removeClass("end");
                        }else{
                            $("#jrsc").addClass("end");
                        }

                    },
                    success: function (data) {
                        if (data) {
                            if(data.status==1){
                                jrsclock = true;
                                alert(data.message);
                            }else{
                                jrsclock = true;
                                alert(data.message);
                            }
                        }else{
                            jrsclock = true;
                            alert('加入收藏失败');
                        }
                    }
                });
            }else{

            }
        });

        var sharelock = true;
        $("#share").click(function(){
            $('#linkModal-d').modal();
        });
        $("#lsshare").click(function(){
            $('#linkModal-e').modal();
        });


    });
    $(function(){
        var h = $(window).height();
        $('.wrap').css("height",h+"px");

    });
    <?php if($status=='no'){ ?>
    $(function(){
        var storage = window.localStorage;
        var stroeUser = storage["stroeUser"];
        $.ajax({
            type: "POST",
            url: '<?php echo Yii::app()->createUrl('user/ajaxCheckUser'); ?>',
            data: {
                stroeUser:stroeUser
            },
            dataType: "json",
            success: function (data) {
                if (data) {
                    if(data.status==1){
                        window.location.reload();
                    }else{
                        window.location.href='<?php echo Yii::app()->createUrl('index/login',array('openid'=>$openid)); ?>';
                    }
                }else{
                    window.location.href='<?php echo Yii::app()->createUrl('index/login',array('openid'=>$openid)); ?>';
                }
            }
        });

    });
    <?php } ?>
    $(function(){
        $("#logout").click(function(){
            if(window.confirm('你确定要退出账号吗？')){
                $.ajax({
                    type: "POST",
                    url: '<?php echo Yii::app()->createUrl('index/ajaxLogout'); ?>',
                    dataType: "json",
                    success: function (data) {
                        if (data) {
                            if(data.status==1){
                                window.localStorage["stroeUser"] = '';
                                window.location.href=data.url;
                            }else{
                                alert('退出失败');
                            }
                        }else{
                            alert('退出失败');
                        }
                    }
                });
            }
        });
    });






    var submitlock = true;
    // AJAX提交数据
    function submitForm() {
        if(submitlock==true){
            var xinde 			= $("#xinde").val();
            if (xinde.length == 0 || xinde.length < 20) {
                alert("心得不能为空或小于20个字符限制");
                return;
            };
            $.ajax({
                type: "POST",
                url: '<?php echo Yii::app()->createUrl('index/ajaxBookComment'); ?>',
                data: {
                    bid:'<?php echo $book_info->id ?>',
                    xinde:xinde
                },
                dataType: "json",
                beforeSend:function(){
                    submitlock = false;
                },
                success: function (data) {
                    if (data) {
                        if(data.status==1){
                            submitlock = true;
                            alert(data.message);
                            $('#linkModal-d').modal('hide');
                            $("#xinde").val('');
                            $("#comm").prepend(data.html);
                        }else{
                            submitlock = true;
                            alert(data.message);
                            $('#linkModal-d').modal('hide');
                            $("#xinde").val('');
                        }
                    }else{
                        submitlock = true;
                        alert('发布心得失败');
                        $('#linkModal-d').modal('hide');
                    }
                }
            });
        }
    };


</script>
<script language="JavaScript" src="<?php echo $this->createUrl('clickCount',array('id'=>$book_info->id)) ?>"></script>